Conversation
…trading - Implement PolymarketAdapter with full CLOB, Gamma, and Data API integration - Add market discovery, position tracking, and order management - Map Polymarket YES/NO tokens to perpetuals long/short positions - Support order placement, cancellation, and position queries - Include risk limits (maxOrderSize, maxOrderNotional) - Remove MCP server implementation in favor of plugin architecture
PR #346 Review - Polymarket PluginSummaryRecommendation: Request Changes - The plugin has critical bugs that prevent it from working. Critical Issues Found1. 🔴 API Response Parsing Bug (CRITICAL)File: The plugin expects the Gamma API to return Current code (line 400): const data = (await response.json()) as PolymarketMarketResponse;
const markets = data.markets.filter(...) // ❌ data.markets is undefined!Should be: const data = (await response.json()) as PolymarketMarket[];
const markets = data.filter(...) // ✅ data IS the arrayResult: Plugin returns 2. 🔴 Wrong
|
0xTomDaniel
left a comment
There was a problem hiding this comment.
Requesting changes - prediction markets must not be modeled as perpetuals. We need a dedicated prediction-markets plugin type, schemas, actions, and queries.
Blocking issues
-
Wrong abstraction: prediction markets are not perpetuals.
- Mapping YES/NO outcomes into
Perpetuals*actions/schemas breaks core semantics (no leverage, funding/borrowing fees, or perpetual position mechanics). This should be a first-classpredictionMarketsplugin type with purpose-built actions/queries/schemas, then port Polymarket to that interface. - Integration points (core registry):
registry/src/core/pluginType.ts-> addpredictionMarketsand extendAvailableActions/AvailableQueries.registry/src/core/actions/predictionMarkets.ts-> new action types + callbacks; export inactions/index.ts; add toActionunion andCallbacksRecordinactions/types.ts.registry/src/core/queries/predictionMarkets.ts-> new query types; export inqueries/index.ts.registry/src/core/schemas/predictionMarkets.ts-> Zod schemas; export inschemas/index.ts.registry/README.md+registry/DEVELOPMENT.md-> document new type, action names, queries, and MCP tools (if exposed).
- Integration points (downstream consumers):
- Search for
PluginTypeorperpetualsenumerations in clients/agents to add the new category where relevant (tool groupings, prompt mappings, UI categories).
- Search for
- Mapping YES/NO outcomes into
-
Lockfile not updated for new deps.
registry/package.jsonadds deps, buttypescript/pnpm-lock.yamlis not updated. Runpnpm installfromtypescript/and commit the lockfile.
-
registerPolymarket drops config options documented in README.
gammaApiUrl/dataApiUrlare documented but never passed. Either plumb them through or remove from docs/type.registry/src/polymarket-perpetuals-plugin/index.ts:115
-
Inconsistent identifiers for market vs outcome tokens.
- Actions treat
marketAddressas a YES token id, while queries returnmarket.idortokenId. This breaks round-trip flows. - New prediction-markets schemas must separate
marketIdfromoutcomeTokenIdexplicitly.
- Actions treat
Suggested prediction-markets abstraction (dense, domain-accurate)
Actions (type names are illustrative):
predictionMarkets-placeOrder- Request:
marketId,outcomeId(oroutcomeTokenId),side(buy/sell),size(shares), optionalprice(limit), optionalquoteTokenAddress, optionaltimeInForce/expiration. - Response:
orderId(if available) +transactions(can be empty for off-chain matching).
- Request:
predictionMarkets-cancelOrder- Request:
orderId+walletAddress. - Response:
transactionsorsuccess.
- Request:
predictionMarkets-redeem/predictionMarkets-claimWinnings- Request:
marketId,outcomeId,walletAddress, optionalamount. - Response:
transactions.
- Request:
Queries:
getMarkets- Request:
chainIds, optional filters:status(active|resolved|voided|paused),category,endTimeBefore/After,minLiquidity,limit/offset.
- Request:
getMarketDetails(optional but strongly useful)- Request:
marketId; Response includes outcomes, prices, status, resolution metadata.
- Request:
getPositions- Request:
walletAddress, optionalmarketIds, optionalincludeResolved.
- Request:
getOrders- Request:
walletAddress, optionalmarketIds,status(open|filled|canceled|expired).
- Request:
Schemas (key fields to keep consistent across protocols):
PredictionMarketmarketId,chainId,title/question,status,endTime,resolutionOutcome(nullable),oracle/source,outcomes[].
PredictionOutcomeoutcomeId,name, optionaltokenId,price(as decimal string),probability(optional if price already normalized),liquidity(optional).
PredictionPositionmarketId,outcomeId, optionaltokenId,size,avgPrice,cost,pnl(optional),quoteTokenAddress.
PredictionOrderorderId,marketId,outcomeId,side,price,size,status,createdAt,updatedAt.
Modeling rules (to avoid future mismatches):
marketId!=outcomeTokenId; never overload.- Do not include leverage/funding/borrowing fields in prediction-market positions; keep it share-based.
- Normalize prices consistently (0-1 probability or quote-token price) and document with an enum if needed.
- Represent resolution explicitly (
resolvedOutcomeIdorvoided) to support redeem/claim flows.
Next steps
- Implement the new prediction-markets plugin type + schemas/actions/queries, migrate Polymarket adapter to it.
- Fix remaining blockers and re-run
pnpm lint+pnpm buildfromtypescript/.
Summary
Related Issue(s):
Provide a brief description of what this PR accomplishes:
Adds a Polymarket perpetuals plugin for the Ember Plugin System, enabling Vibekit agents to trade on Polymarket prediction markets. The plugin maps Polymarket's YES/NO token model to perpetuals long/short positions, with market discovery, position tracking, order placement, and cancellation.
Type of Change:
🧪 Testing
Tests Performed:
pnpm build)pnpm lint)Test Results:
Steps to Run Tests:
Checklists
Code Quality
pnpm build)pnpm lint)pnpm test) - Integration tests pending API credentialsanytypes introduced (usesunknownwith proper type guards)Documentation
Agent/MCP Specific (if applicable)
Deployment Notes
Deployment Considerations:
registerPolymarket()parametersNew or Changed Environment Variables:
POLYMARKET_HOST,POLYMARKET_GAMMA_API_URL,POLYMARKET_DATA_API_URLcan be configured via adapter paramsBreaking Changes or Migration Steps:
New Dependencies Added:
@polymarket/clob-client(^4.22.8) - Official Polymarket CLOB client@ethersproject/wallet(^5.7.2) - Already in dependencies, used for signingAdditional Context
Screenshots or Demo Videos (if applicable):
Implementation Details:
perpetuals(maps prediction markets to derivatives model)perpetuals-long→ BUY YES tokensperpetuals-short→ BUY NO tokensperpetuals-close→ Cancel ordersgetMarkets- Fetches active markets from Gamma APIgetPositions- Fetches user positions from Data API (with CLOB fallback)getOrders- Fetches pending orders from CLOB ledgerhttps://gamma-api.polymarket.com) - Market datahttps://clob.polymarket.com) - Order executionhttps://data-api.polymarket.com) - User positionsmaxOrderSizeandmaxOrderNotionallimits